package com.djsearch.adapter;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.djsearch.R;
import com.djsearch.bean.MyCollect;
import com.djsearch.data.ImageManager;
import com.djsearch.data.RequestImage;

public class MyCollectListViewAdapter extends BaseAdapter{
	
	private Context mContext;
	private List<MyCollect> myCollcetList;
	private Bitmap mbitmap;
	public MyCollectListViewAdapter(Context context,List<MyCollect> list) {
		mContext = context;
		myCollcetList = list;
		Bitmap bitmap = ImageManager.drawableToBitmap(mContext.getResources().getDrawable(R.drawable.taogou),150.0f);
		mbitmap = (ImageManager.resizeImage(bitmap, 150.0f));
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return myCollcetList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return myCollcetList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}
	
	public void refreshData(List<MyCollect> list)
	{
		myCollcetList = list;
		notifyDataSetChanged();
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		
		if (convertView == null) {
			LayoutInflater layoutInflater = ((Activity) mContext).getLayoutInflater();
			convertView = layoutInflater.inflate(R.layout.collect_list_item, parent, false);
			convertView.setTag(convertView);
		} else {
			convertView = (View) convertView.getTag();
		}
		//商品图片
		final ImageView goodsImg = (ImageView)convertView.findViewById(R.id.goodsImg);
		RequestImage.getIntance(mbitmap, "GroupShop").download(myCollcetList.get(position).getSmallImage(), 
				goodsImg);
		//商品名字
		TextView shopName = (TextView)convertView.findViewById(R.id.goodsName);
		shopName.setText(myCollcetList.get(position).getName());
		//商品的描述
		TextView goodsDescribe = (TextView)convertView.findViewById(R.id.goodsDescribe);
		goodsDescribe.setText(myCollcetList.get(position).getDescription());
		//商品地址
		TextView place = (TextView)convertView.findViewById(R.id.place);
		place.setText(myCollcetList.get(position).getPlace());
		return convertView;
	}
	

}
